package com.my.blog.website.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

/**
 * desc
 *
 * @author leihz
 * @date 2017/6/23 18:00
 */
public class ServletUtils {

        private HashMap<String,Object> paramMap = new HashMap<String,Object>();
        private HttpServletRequest request;
        private HttpServletResponse response;
        private HttpSession session;

        public void setParam(String key,Object value){
            this.paramMap.put(key,value);
        }

        public HashMap<String, Object> getParamMap() {
            return this.paramMap;
        }

        public void clearParamMap() {
            this.paramMap.clear();
        }

        public static HttpServletRequest getRequest() {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        }

        public static HttpServletResponse getResponse() {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        }

        public static HttpSession getSession() {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
        }
}
